import 'package:get_storage/get_storage.dart';

class StorageUtil{


  static void saveData(String key,String value){
    GetStorage storageBox = GetStorage();
    storageBox.write(key, value);
   //  _store.setString(key, value);
  }

  static void saveDynamicData(String key,dynamic value){
    GetStorage storageBox = GetStorage();
    storageBox.write(key, value);
    //  _store.setString(key, value);
  }

  static dynamic getData(String key){
    GetStorage storageBox = GetStorage();
    return  storageBox.read(key);
  }


  static dynamic getLoginAccount(){
    dynamic account=getData("cache_account");
    if(account==null||account.isEmpty){
      account="";
    }
     return account;
  }

  static void clearKey(String key){
    GetStorage storageBox = GetStorage();
    storageBox.remove(key);
  }

  static void saveLoginAccount(String account){
    if(account.isEmpty){
      clearKey("cache_account");
      return;
    }
    saveData("cache_account",account);
  }

  static dynamic getLoginPwd(){

    return getData("cache_pwd");
  }

  static void saveLoginPwd(String pwd){
    if(pwd.isEmpty){
      clearKey("cache_pwd");
      return;
    }
    saveData("cache_pwd",pwd);
  }

  static void saveToken(String token){
    if(token.isEmpty){
      clearKey("cache_token");
      return;
    }
     saveData("cache_token",token);
    }

  static  dynamic getToken(){

       return getData("cache_token");
    }

  static void saveRoleCode(String token){
    if(token.isEmpty){
      clearKey("cache_rolecode");
      return;
    }
    saveData("cache_rolecode",token);
  }

  static  dynamic getRoleCode(){

    return getData("cache_rolecode");
  }

  static void saveUserId(String token){
    saveData("cache_userId",token);
  }

  static dynamic getUserId(){

    return getData("cache_userId");
  }
  static void saveUserName(String token){
    saveData("cache_username",token);
  }

  static dynamic getUserName(){

    return getData("cache_username");
  }
  static void saveDiscount(String token){
    if(token==null||token.isEmpty){
      token="0";
    }
    saveData("cache_discount",token);
  }
  static dynamic getUserDiscount(){
    String discount=getData("cache_discount");
    if(discount==null||discount.isEmpty){
      discount="0";
    }
    return discount;
  }
  static void saveRoleName(String token){
    if(token==null||token.isEmpty){
      token="";
    }
    saveData("cache_rolename",token);
  }
  static dynamic getUserRoleName(){
    dynamic discount=getData("cache_rolename");
    if(discount==null||discount.isEmpty){
      discount="";
    }
    return discount;
  }

  static dynamic getCurrency(){
    return getData("cache_currency");
  }

  static void saveCurrency(String currency){
    saveData("cache_currency", currency);
  }

  static dynamic getCurrencyRate(){
    return getData("cache_currency_rate");
  }


  static void saveMenu(List menu){
    saveDynamicData("cache_menu", menu);
  }

  static dynamic getMenu(){
    return getData("cache_menu");
  }


  static void saveMenuButton(List menu){
    saveDynamicData("cache_menu_button", menu);
  }

  static dynamic getMenuButton(){
    return getData("cache_menu_button");
  }


  static void saveCurrencyRate(String currencyRate){
    saveData("cache_currency_rate", currencyRate);
  }

  static void saveRate1(String currency){
    saveData("cache_rate1", currency);
  }

  static dynamic getRate1(){
    return getData("cache_rate1");
  }
  static void saveRate2(String currency){
    saveData("cache_rate2", currency);
  }

  static dynamic getRate2(){
    return getData("cache_rate2");
  }

  static bool checkLogin(){
    var userModel=getToken();
    if(userModel ==null ){
      return false;
    }else{
      return true;
    }
  }

}